/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import bdd.DBLink;
import java.sql.Date;

/**
 *
 * @author maboisba
 */
public class ListeTypes {

  //private DBLink dblink;
  List<Type> listeTypes;

  public ListeTypes() {
      //dblink = new DBLink();
    listeTypes = new ArrayList<Type>();
  }

  public ListeTypes(List<Type> listeTypes) {
     // dblink = new DBLink();
    this.listeTypes = listeTypes;
  }

  public List<Type> getListeTypes() {
    return listeTypes;
  }

  public void setListeTypes(List<Type> listeTypes) {
    this.listeTypes = listeTypes;
  }

  public void add(Type type) {
    listeTypes.add(type);
  }

  public void recupererListeTypes(){
        int numType;
        String libelleType;
        try {
            //PreparedStatement pst = this.dblink.getConnection().prepareStatement("SELECT ENSEIGNANT.NOM, SUM(JNTTYPEECENSEIGNANT.) FROM ENSEIGNANT, JNTTYPEECENSEIGNANT"
            //        + "WHERE ENSEIGNANT.numenseignant = JNTTYPEECENSEIGNANT.numenseignant");
            DBLink db = new DBLink();
            db.connexion();
            PreparedStatement pst = db.getConnection().prepareStatement("SELECT * FROM type");
            db.setPst(pst);
            ResultSet rs = db.getPst().executeQuery();
            db.setRs(rs);
            while(db.getRs().next()){
                numType = db.getRs().getInt("numtype");
                libelleType = db.getRs().getString("libelle");
                Type t = new Type(numType, libelleType);
                this.listeTypes.add(t);
            }
            db.getConnection().close();
        } catch (SQLException ex) {
            Logger.getLogger(ListeTypes.class.getName()).log(Level.SEVERE, null, ex);
        }
  }
}
